import requests

from api import log
from api.api_factory import ApiFactory
from tools import html_parser


class TestTendetList():
    def setup_method(self):
        self.session = requests.session()
        self.api = ApiFactory(self.session)

    def teardown_method(self):
        self.session.close()

    def test01_tender_list(self):
        try:
            # 获取图片验证码接口
            self.api.get_register_login().api_img_code(123456)
            # 获取短信验证码
            self.api.get_register_login().api_phone_code('13611112222', "8888")
            # 注册接口
            self.api.get_register_login().api_register('13611112222', 'test123', '8888', '666666')
            # 登录接口
            self.api.get_register_login().api_login()
            # 认证接口
            self.api.get_approve().api_approve()
            # 后台开户接口
            result = self.api.get_approve().api_trust()
            # 三方开户接口
            data = html_parser(result)
            result = self.session.post(url=data[0], data=data[1])
            log.info("三方开户执行结果为:{}".format(result.text))
            # 充值验证码接口
            self.api.get_recharge().api_img_code(123456)
            # 后台充值接口
            result = self.api.get_recharge().api_recharge()
            # 三方充值接口
            data = html_parser(result)
            result = self.session.post(url=data[0], data=data[1])
            log.info("三方充值执行结果为:{}".format(result.text))
            # 后台投资接口
            result = self.api.get_tender().api_tender(100)
            # 三方投资接口
            data = html_parser(result)
            result = self.session.post(url=data[0], data=data[1])
            log.info("三方投资执行结果为:{}".format(result.text))
        except Exception as e:
            log.error(e)
            raise